package sim;

import java.util.LinkedList;

import tWeight.WeightDist;

import matrics.SparseVector;
import myLucene.Props;

public class DistVector {
	public static SparseVector distToSparseVectors(LinkedList<Integer> ll)
			throws Exception {
		int spSize = Props.windowSize / Props.distanceSectionsLength;
		if ((Props.windowSize % Props.distanceSectionsLength ) > 0) {
			spSize+= 2;
		}
		if(spSize%2 >0){
			spSize++;
		}
		SparseVector distSp = new SparseVector((spSize));

		for (int x : ll) {
			if(ll.size()<20){
				break;
			}
			if (x < 0) {
				int absoluteX = Math.abs(x);
				double sect = (double) absoluteX
						/ (double) Props.distanceSectionsLength;
				int upRoundedSect = absoluteX / Props.distanceSectionsLength;

				if ((sect % 1) > 0) {
					upRoundedSect = upRoundedSect + 1;
				}
				int position = (distSp.size() / 2) - upRoundedSect;

//				System.out.println("Dist Vector size: " + (distSp.size())
//						+ " value: " + x + " section " + upRoundedSect
//						+ " position " + position);
				double valBefore = distSp.get(position);
				distSp.put(position, valBefore + 1.0);
			}
			if (x > 0) {

				double sect = (double) x
						/ (double) Props.distanceSectionsLength;
				int upRoundedSect = x / Props.distanceSectionsLength;

				if ((sect % 1) > 0) {
					upRoundedSect = upRoundedSect + 1;
				}
				int position = (distSp.size() / 2) + upRoundedSect - 1;
				
//				System.out.println("Dist Vector size: " + (distSp.size())
//						+ " value: " + x + " section " + upRoundedSect
//						+ " position " + position);
				double valBefore = distSp.get(position);
				distSp.put(position, valBefore + 1.0);
			}

		}
		
		SparseVector weightedDistSp=WeightDist.weightDist(distSp);
		//Cosin.printSparseVector(weightedDistSp);
		return weightedDistSp;
	}
}
